import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import os

# 打开访问地址
driver = webdriver.Chrome()
url = 'file:///' + os.path.abspath(('html') + '/注册实例.html')
driver.get(url)



# 获取alert点击按钮
alert = driver.find_element(By.ID, 'alert').click()

# 切换到弹窗
time.sleep(2)
alter = driver.switch_to.alert
alter.accept()   # 确定

# 切换到指定frame1
driver.switch_to.frame('idframe1')

# 获取alerta点击按钮
time.sleep(2)
altera = driver.find_element(By.ID, 'alerta').click()

# 切换到弹窗a
time.sleep(2)
alter = driver.switch_to.alert
alter.accept()   # 确定

# 切换到指定frame2
# 切换到父级frame
driver.switch_to.parent_frame()
driver.switch_to.frame('myframe2')

# 获取alertb点击按钮
time.sleep(2)
alterb = driver.find_element(By.ID, 'alertB').click()


# 切换到弹窗b
time.sleep(2)
alter = driver.switch_to.alert
alter.accept()   # 确定

driver.quit()